package com.xyl.intercept;

import com.xyl.entity.User;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AuthInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User user = (User) request.getSession().getAttribute("cur_user");
        if (ObjectUtils.isEmpty(user)) {
            response.sendRedirect("/login");
            return false;
        }
        return true;
    }
}
